package com.ruoyi.pay.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_Topic {
    private static final String QUEUE_NAME_1 = "Queue_PaySuccess_T1";
    private static final String QUEUE_NAME_2 = "Queue_PaySuccess_T2";
    private static final String QUEUE_NAME_3 = "Queue_PaySuccess_T3";

    private static final String EX_NAME = "exchange_topic_paySuccess";

    //队列
    @Bean(QUEUE_NAME_1)
    public Queue Queue_PaySuccess_T1(){
        return QueueBuilder.durable(QUEUE_NAME_1).build();
    }

    @Bean(QUEUE_NAME_2)
    public Queue Queue_PaySuccess_T2(){
        return QueueBuilder.durable(QUEUE_NAME_2).build();
    }

    @Bean(QUEUE_NAME_3)//队列持久化durable
    public Queue Queue_PaySuccess_T3(){
        return QueueBuilder.durable(QUEUE_NAME_3).build();
    }


    //交换机
    @Bean(EX_NAME)
    public Exchange exchangeDeclare_topic(){
        return ExchangeBuilder.topicExchange(EX_NAME).durable(true).build();//交换机持久化true
    }

    //Binding
    @Bean
    public Binding BINGDING_PAY_SUCCESS_T1(@Qualifier(EX_NAME) Exchange exchange,
                                       @Qualifier(QUEUE_NAME_1) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.order.#").noargs();
    }

    @Bean
    public Binding BINGDING_PAY_SUCCESS_T2(@Qualifier(EX_NAME) Exchange exchange,
                                       @Qualifier(QUEUE_NAME_2) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.bounds.#").noargs();
    }

    @Bean
    public Binding BINGDING_PAY_SUCCESS_T3(@Qualifier(EX_NAME) Exchange exchange,
                                         @Qualifier(QUEUE_NAME_3) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.warehouse.#").noargs();
    }

}
